<?php
/***
 * 描述：购物车页面
 * @category		WWW		
 * @package			Action			
 * @subpackage		
 * @author			wanght <whtaok@gmail.com>
 * @since			2013-4-6
 * @version			$Id: CartAction.class.php 12 2013-10-22 08:31:42Z whtaok@gmail.com $
 */
class CartAction extends WwwAction {
	/**
	 * 描述：购物车列表
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-3-3
	 */
	public function indexAct() {
		//购物车信息
		$this->setPageTitle('我的购物车');
		$cart = CartModel::getCart(session(SES_SHOP_ID));
		$this->assign('cartItems',$cart['cartItems']);
		$this->assign('cartPrice',$cart['cartPrice']);
		$this->display('index');
	}
	
	
	/**
	 * 描述：商品放入购物车 type==1 增加  type==2 更新
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-3-3
	 */
	public function doAddAct() {
		//输入校验
		$num = I('num');
		$prod_id = I('prod_id');
		if(check_cartitemnum($num)===false){
			$this->ajaxReturn(array('error'=>'1','message'=>'购买数量输入不正确'));
			exit();
		}
		if(!$prod_id){
			$this->ajaxReturn(array('error'=>'1','message'=>'请选择商品'));
			exit();
		}
		$num = intval($num);
		$stock_ref = get_prod_stock_ref($prod_id);
		$rtnData = CartModel::addToCart(session(SES_SHOP_ID), $prod_id, $num,$stock_ref['spec_qty'],$stock_ref['stock_prod_id'],I('edittype'));
		$this->ajaxReturn($rtnData);
	}
	
	/**
	 * 描述：清空购物车
	 * @access		public
	 * @author		wanght<whtaok@gmail.com>
	 * @since		2013-3-3
	 */
	public function doEmptyAct() {
		cookie(COK_CART,null);
		$this->success('购物车已清空！');
	}
	
}

?>